var run = new Object();
run.randomNum = function (rum) {
    var num = (Math.floor(Math.random() * rum) + 1);
    return num;
}
run.selectNum = function (min, max) {
    var num = run.randomNum(360);
    if ((num < (max - 20)) && ((min + 20) < num)) {
        console.log(num);
        return num;
    } else {
        return run.selectNum(min, max);
    }
}
run.parity = function (data) {
    var rNum = run.randomNum(3);
    if (data) {
        rNum = rNum * 2;
    } else {
        rNum = rNum * 2 - 1;
    }
    return rNum;
}
run.time = function (sum, value) {
    var num = 0;
    var timer = setInterval(function () {
        if (num == (sum + 360)) {
            clearInterval(timer);

            if (value == 0) {
                alert('您未中奖');
            }
            else {
                alert('您中了' + value + '元');
            }
        } else {
            num++;
            run.move(".outer", num);
        }
    }, 4);
}
run.move = function (ele, rt) {
    $(ele).css({
        "transform": "rotate(" + rt + "deg)"
    });
}

$(function(){
    $(".button").on("click", function () {
        var value = 0;
        rNum = run.parity(value > 0 ? 0 : 1);
        var max = rNum * 60;
        var min = (rNum - 1) * 60;
        console.log(max, min);
        if (value) {
            var sum = run.selectNum(min, max);
            console.log(sum);
        } else {
            var sum = run.selectNum(min, max);
            console.log(sum);
        }
        //sum=28+60+60+60+60+60;
        run.time(sum, value);
    });
});